﻿Public Class FormInvoice

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim frm As New FormInvoiceEditor
        frm.Show()

    End Sub

    Private Sub FormInvoice_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        UI.FormatDataGrid(Me.dgv)
        LoadData()
    End Sub
    Private Sub LoadData()
        'Dim sql As String
        'If DateTimePicker1.Value.Day = Date.Today.Day And Me.TextBox1.Text = "" Then
        '    sql = "select * from Invoice"
        'Else
        '    sql = "select * from Invoice where InvoiceDate between @d1 and @d2 and InvoiceNo like '%'+@code+'%'"
        'End If
        'Me.dgv.DataSource = Cmd.ExecuteDataTable(sql)
        Cmd.Parameters("@d1") = Me.DateTimePicker1.Value
        Cmd.Parameters("@d2") = Me.DateTimePicker2.Value
        Cmd.Parameters("@code") = Me.TextBox1.Text
        Me.dgv.DataSource = Cmd.ExecuteDataTable("select * from Invoice where InvoiceDate between @d1 and @d2 and InvoiceNo like '%'+@code+'%'")
    End Sub

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        LoadData()
    End Sub

    Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
        'Me.dgv.DataSource = Cmd.ExecuteDataTable("select * from Invoice where InvoiceDate between '" & Me.DateTimePicker1.Value & "' and '" & Me.DateTimePicker2.Value & "' ")
        LoadData()

    End Sub

    Private Sub DateTimePicker2_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker2.ValueChanged
        'Me.dgv.DataSource = Cmd.ExecuteDataTable("select * from Invoice where InvoiceDate between '" & Me.DateTimePicker1.Value & "' and '" & Me.DateTimePicker2.Value & "' ")
        LoadData()
    End Sub
End Class